<app-indexing-progress *ngIf="!widget"></app-indexing-progress>

<div [class]="widget === false ? 'full-container' : ''">

  <div *ngIf="widget">
    <div class="pool-distribution" *ngIf="(hashrateObservable$ | async) as hashrates; else loadingStats">
      <div class="item">
        <h5 class="card-title" i18n="mining.hashrate">Hashrate (1w)</h5>
        <p class="card-text">
          {{ hashrates.currentHashrate | amountShortener: 3 : 'H/s' : false : true }}
        </p>
      </div>
      <div class="item">
        <h5 class="card-title" i18n="block.difficulty">Difficulty</h5>
        <p class="card-text" *ngIf="network === 'signet'">
          {{ hashrates.currentDifficulty | amountShortener : 5 }}
        </p>
        <p class="card-text" *ngIf="network !== 'signet'">
          {{ hashrates.currentDifficulty | amountShortener : 2 }}
        </p>
      </div>
    </div>
  </div>

  <div class="card-header mb-0 mb-md-4" [style]="widget ? 'display:none' : ''">
    <div class="d-flex d-md-block align-items-baseline">
      <span i18n="mining.hashrate-difficulty">Hashrate & Difficulty</span>
      <button class="btn p-0 pl-2" style="margin: 0 0 4px 0px" (click)="onSaveChart()">
        <fa-icon [icon]="['fas', 'download']" [fixedWidth]="true"></fa-icon>
      </button>
    </div>  

    <form [formGroup]="radioGroupForm" class="formRadioGroup" *ngIf="(hashrateObservable$ | async) as stats">
      <div class="btn-group btn-group-toggle" name="radioBasic">
        <label class="btn btn-primary btn-sm" *ngIf="stats.blockCount >= 12960" [class.active]="radioGroupForm.get('dateSpan').value === '3m'">
          <input type="radio" [value]="'3m'" fragment="3m" [routerLink]="['/graphs/mining/hashrate-difficulty' | relativeUrl]" [attr.data-cy]="'3m'" formControlName="dateSpan"> 3M
        </label>
        <label class="btn btn-primary btn-sm" *ngIf="stats.blockCount >= 25920" [class.active]="radioGroupForm.get('dateSpan').value === '6m'">
          <input type="radio" [value]="'6m'" fragment="6m" [routerLink]="['/graphs/mining/hashrate-difficulty' | relativeUrl]" [attr.data-cy]="'6m'" formControlName="dateSpan"> 6M
        </label>
        <label class="btn btn-primary btn-sm" *ngIf="stats.blockCount >= 52560" [class.active]="radioGroupForm.get('dateSpan').value === '1y'">
          <input type="radio" [value]="'1y'" fragment="1y" [routerLink]="['/graphs/mining/hashrate-difficulty' | relativeUrl]" [attr.data-cy]="'1y'" formControlName="dateSpan"> 1Y
        </label>
        <label class="btn btn-primary btn-sm" *ngIf="stats.blockCount >= 105120" [class.active]="radioGroupForm.get('dateSpan').value === '2y'">
          <input type="radio" [value]="'2y'" fragment="2y" [routerLink]="['/graphs/mining/hashrate-difficulty' | relativeUrl]" [attr.data-cy]="'2y'" formControlName="dateSpan"> 2Y
        </label>
        <label class="btn btn-primary btn-sm" *ngIf="stats.blockCount >= 157680" [class.active]="radioGroupForm.get('dateSpan').value === '3y'">
          <input type="radio" [value]="'3y'" fragment="3y" [routerLink]="['/graphs/mining/hashrate-difficulty' | relativeUrl]" [attr.data-cy]="'3y'" formControlName="dateSpan"> 3Y
        </label>
        <label class="btn btn-primary btn-sm" [class.active]="radioGroupForm.get('dateSpan').value === 'all'">
          <input type="radio" [value]="'all'" fragment="all" [routerLink]="['/graphs/mining/hashrate-difficulty' | relativeUrl]" [attr.data-cy]="'all'" formControlName="dateSpan"> ALL
        </label>
      </div>
    </form>
  </div>

  <div [class]="!widget ? 'chart' : 'chart-widget'" *browserOnly [style]="{ height: widget ? ((height + 20) + 'px') : null, opacity: isLoading ? 0.5 : 1 }" echarts [initOpts]="chartInitOptions" [options]="chartOptions"
    (chartInit)="onChartInit($event)">
  </div>
  <div class="text-center loadingGraphs" *ngIf="!stateService.isBrowser || isLoading">
    <div class="spinner-border text-light"></div>
  </div>

</div>

<ng-template #loadingStats>
  <div class="pool-distribution">
    <div class="item">
      <h5 class="card-title" i18n="mining.hashrate">Hashrate</h5>
      <p class="card-text">
        <span class="skeleton-loader skeleton-loader-big"></span>
      </p>
    </div>
    <div class="item">
      <h5 class="card-title" i18n="block.difficulty">Difficulty</h5>
      <p class="card-text">
        <span class="skeleton-loader skeleton-loader-big"></span>
      </p>
    </div>
  </div>
</ng-template>
